package com.itheima.utils;

/**
 * @Description ThreadLocalUtil
 * @Author songyu
 * @Date 2025-01-14  9:09
 */
public class ThreadLocalUtil {

    //定义一个ThreadLocal存储员工id
    //每个线程都会创建这个对象的副本，最后每个线程都有自己的 loginIdThreadLocal
    private static ThreadLocal<Integer> loginIdThreadLocal = new ThreadLocal<>();

    /**
     * 写入数据
     * @param empId
     */
    public static void setLoginId(Integer empId){
        loginIdThreadLocal.set(empId);
    }

    /**
     * 读取数据
     * @return
     */
    public static Integer getLoginId(){
        return loginIdThreadLocal.get();
    }

    /**
     * 删除数据
     */
    public static void removeLoginId(){
        loginIdThreadLocal.remove();
    }

}
